package com.geping.etl.common.controller.security.pwd;

import com.geping.etl.common.security.pwd.PwdPolicyService;
import com.geping.etl.common.security.pwd.PwdPolicyServiceDispatcher;
import com.geping.etl.common.util.BusinessResponse;
import com.geping.etl.common.util.BusinessResult;

import com.geping.etl.common.util.Constants;
import com.geping.etl.utils.EnvUitl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/***
 *  密码策略服务
 * @author liang.xu
 * @date 2021.10.27
 */
@RestController
@Slf4j
public class PwdPolicyController {

    /**
     * 校验密码
     * @return
     */
    @RequestMapping(value = "/checkPwd", method = RequestMethod.POST)
    public BusinessResult checkPwd(String pwd){
        PwdPolicyService pwdPolicyService=PwdPolicyServiceDispatcher.getPwdPolicyService(EnvUitl.props.getProperty(Constants.PWD_POLICY_CUSTOMER));
        if(!pwdPolicyService.validate(pwd)){
            BusinessResponse businessResponse=BusinessResponse.FAIL;
            businessResponse.setDesc(pwdPolicyService.getPwdPolicy().getTip());
            return new BusinessResult(businessResponse);
        }
        return new BusinessResult(BusinessResponse.SUCCESS);
    }

}